#!/usr/bin/env bash
workspace="/opt/crm/code"
pomFile="pom.xml"
currentBranch="dev"
jarName="crm-job"
addr="192.168.212.3"
gitupdate(){
  mkdir -p ${workspace}
  cd ${workspace} || exit
  echo "进入目录"
  if [[ ! -f "/$pomFile/" ]]; then
    git clone --branch=${currentBranch} --depth=1 git@10.50.10.214:hyn-dc-crm-java/crm.git ${workspace}
  else
    git checkout ${currentBranch}
    git pull
  fi
}
mvnpack() {
  cd ${workspace} || exit
  mvn clean package -Dmaven.Test.skip=true
  sleep 5
  if [[ $? -eq 0 ]]; then
    echo "mvn clean package is ok"
  else
    exit
    echo "mvn clean package is faild"
  fi
}
bak() {
  ssh root@"${addr}" "sh /crm/bak.sh ${jarName}"
}
scpJar() {
  cd ${workspace} || exit
  scp "./crm-web/${jarName}/target/${jarName}.jar" "root@${addr}:/crm/${jarName}"
  ssh root@${addr} "sh /crm/restart.sh ${jarName}"
}
gitupdate
mvnpack
#bak
scpJar
